package gomz.pres.admin;

import gomz.pres.GUIMain;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

/**
 * Diese Klasse erstellt das GUI der Accountdaten in der Verwaltung
 * 
 * @author Dilji
 */

public class GUIAAccount {

	// all the variables for main panels
	private JPanel plAccount;
	private JPanel plAccountNord;
	private JScrollPane spAccount;

	// all the variables
	private JLabel lbAaccountTitle;
	private JLabel lbAuser;
	private JTextField tfAuser;
	private JLabel lbApw;
	private JPasswordField pfApw;
	private JLabel lbAfirstname;
	private JTextField tfAfirstname;
	private JLabel lbAlastname;
	private JTextField tfAlastname;
	private JLabel lbAemail;
	private JTextField tfAemail;
	private JLabel lbAlang;
	private JLabel lbApflichtfelder;
	private JComboBox cxAlang;
	private JButton btAsave;
	private JButton btAcan;

	/**
	 * Konstruktor der eigenen Accountdaten-Sicht
	 * 
	 * @param b gibt an, ob in der Verwaltungssicht 
	 * oder Registrieren-Fenster beim Login
	 */
	public GUIAAccount(boolean b) {

		// initialize the panels, add to scrollpane and set position
		this.plAccount = new JPanel();
		this.plAccountNord = new JPanel();
		this.spAccount = new JScrollPane(plAccountNord);
		this.plAccountNord.setLayout(new BorderLayout());
		this.plAccountNord.setBorder(new EmptyBorder((2 * GUIMain.getAbstand()), 0, GUIMain.getAbstand(), 0));
		this.plAccountNord.add(plAccount, BorderLayout.NORTH);

		// wenn b true dann Ansicht Benutzer registireren, wenn false
		// Benutzerverwaltung 'Mein Account'
		if (b) {
			// Titel Registration
			this.lbAaccountTitle = new JLabel("Neuer Benutzer");
			// background color Registration
			this.plAccount.setBackground(GUIMain.getBgblue());
			this.plAccountNord.setBackground(GUIMain.getBgblue());
			// buttons Registration
			this.btAsave = new JButton("Benutzer erstellen");
			this.btAcan = new JButton("Abbrechen");
		} else {
			// Titel Benutzerverwaltung
			this.lbAaccountTitle = new JLabel("Mein Account");
			// background color Benutzerverwaltung
			this.plAccount.setBackground(Color.WHITE);
			this.plAccountNord.setBackground(Color.WHITE);
			// buttons Benutzerverwaltung
			this.btAsave = new JButton("Speichern");
			this.btAcan = new JButton("Zur\u00fccksetzen");
		}
	}

	/**
	 * Diese Methode erstellt das GUI fuer die Accountdaten-Sicht
	 * 
	 * @return gibt GUI zurueck
	 */
	public JScrollPane getTab() {

		// initialize the components of overview
		String listLang[] = { "Deutsch", "Englisch" };
		this.lbAuser = new JLabel("Benutzername: *");
		this.tfAuser = new JTextField();
		this.lbApw = new JLabel("Passwort: *");
		this.pfApw = new JPasswordField();
		this.lbApflichtfelder = new JLabel("* Pflichtfelder");
		this.lbAfirstname = new JLabel("Vorname:");
		this.tfAfirstname = new JTextField();
		this.lbAlastname = new JLabel("Nachname:");
		this.tfAlastname = new JTextField();
		this.lbAemail = new JLabel("E-Mail:");
		this.tfAemail = new JTextField();
		this.lbAlang = new JLabel("Sprache:");
		this.cxAlang = new JComboBox(listLang);

		// FontSize for title
		this.lbAaccountTitle.setFont(GUIMain.getTitlefont());
		this.lbAaccountTitle.setForeground(GUIMain.getTitleblue());

		// size of buttons
		this.btAsave.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btAsave.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btAcan.setPreferredSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));
		this.btAcan.setMaximumSize(new Dimension(GUIMain.getBtwidth(), GUIMain.getBtheight()));

		// set border color
		this.tfAuser.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.pfApw.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.tfAfirstname.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.tfAlastname.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.tfAemail.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));
		this.cxAlang.setBorder(BorderFactory.createCompoundBorder(GUIMain.getBorderColor(), GUIMain.getBorderInGap()));

		// set of textfields
		this.tfAuser.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfAuser.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.pfApw.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.pfApw.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfAfirstname.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfAfirstname.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfAlastname.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfAlastname.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfAemail.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.tfAemail.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));
		this.cxAlang.setPreferredSize(new Dimension(0, GUIMain.getTfheight()));
		this.cxAlang.setMaximumSize(new Dimension(0, GUIMain.getTfheight()));

		// BOX
		Box btAbox = Box.createHorizontalBox();
		btAbox.add(btAsave);
		btAbox.add(Box.createHorizontalStrut(GUIMain.getAbstand()));
		btAbox.add(btAcan);

		// scroll speed
		this.spAccount.getVerticalScrollBar().setUnitIncrement(GUIMain.getScrollspeed());

		// position of components
		this.plAccount.setLayout(new GridBagLayout());
		GridBagConstraints ca = new GridBagConstraints();
		ca.fill = GridBagConstraints.HORIZONTAL; // in x-Achse ausf�llen
		ca.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ca.anchor = GridBagConstraints.NORTHWEST; // Ausrichtung oben

		ca.gridx = 0; // Spalte 1
		ca.gridy = 0; // Zeile 1
		ca.gridwidth = 2;
		plAccount.add(lbAaccountTitle, ca); // label AccountTitle
		ca.gridx = 1; // Spalte 2
		ca.gridy = 0; // Zeile 1
		ca.gridwidth = 1;
		// plAccount.add(, ca); // Com

		ca.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ca.gridx = 0; // Spalte 1
		ca.gridy = 1; // Zeile 2
		plAccount.add(lbAuser, ca); // Label User
		ca.gridx = 1; // Spalte 2
		ca.gridy = 1; // Zeile 2
		plAccount.add(tfAuser, ca); // TextField User

		ca.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ca.gridx = 0; // Spalte 1
		ca.gridy = 2; // Zeile 3
		plAccount.add(lbApw, ca); // Label Passwort
		ca.gridx = 1; // Spalte 2
		ca.gridy = 2; // Zeile 3
		plAccount.add(pfApw, ca); // PasswordField Passwort

		ca.insets = new Insets((GUIMain.getAbstand() / 3), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ca.gridx = 0; // Spalte 1
		ca.gridy = 3; // Zeile 4
		// plAccount.add(, ca); // Leer
		ca.gridx = 1; // Spalte 2
		ca.gridy = 3; // Zeile 4
		plAccount.add(lbApflichtfelder, ca); // Pflichtfelder

		ca.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ca.gridx = 0; // Spalte 1
		ca.gridy = 4; // Zeile 5
		plAccount.add(lbAfirstname, ca); // Label Vorname
		ca.gridx = 1; // Spalte 2
		ca.gridy = 4; // Zeile 5
		plAccount.add(tfAfirstname, ca); // TextField Vorname

		ca.insets = new Insets(GUIMain.getAbstand(), GUIMain.getAbstand(), 0, GUIMain.getAbstand());
		ca.gridx = 0; // Spalte 1
		ca.gridy = 5; // Zeile 6
		plAccount.add(lbAlastname, ca); // Label Nachname
		ca.gridx = 1; // Spalte 2
		ca.gridy = 5; // Zeile 6
		plAccount.add(tfAlastname, ca); // TextField Nachname

		ca.gridx = 0; // Spalte 1
		ca.gridy = 6; // Zeile 7
		plAccount.add(lbAemail, ca); // Label E-Mail
		ca.gridx = 1; // Spalte 2
		ca.gridy = 6; // Zeile 7
		plAccount.add(tfAemail, ca); // TextField E-Mail

		ca.gridx = 0; // Spalte 1
		ca.gridy = 7; // Zeile 8
		plAccount.add(lbAlang, ca); // Label Sprache
		ca.gridx = 1; // Spalte 2
		ca.gridy = 7; // Zeile 8
		plAccount.add(cxAlang, ca); // ComboBox Sprache

		ca.insets = new Insets(((5 / 2) * GUIMain.getAbstand()), GUIMain.getAbstand(), GUIMain.getAbstand(), GUIMain.getAbstand());
		ca.gridx = 0; // Spalte 1
		ca.gridy = 8; // Zeile 9
		// plAccount.add(, ca); // Com
		ca.gridx = 1; // Spalte 2
		ca.gridy = 8; // Zeile 9
		plAccount.add(btAbox, ca); // Box

		return (spAccount);
	}

	// ********************************************************************************
	// Getters und Setters
	// ********************************************************************************

	public JTextField getTfAuser() {
		return tfAuser;
	}

	public void setTfAuser(JTextField tfAuser) {
		this.tfAuser = tfAuser;
	}

	public JPasswordField getPfApw() {
		return pfApw;
	}

	public void setPfApw(JPasswordField pfApw) {
		this.pfApw = pfApw;
	}

	public JTextField getTfAfirstname() {
		return tfAfirstname;
	}

	public void setTfAfirstname(JTextField tfAfirstname) {
		this.tfAfirstname = tfAfirstname;
	}

	public JTextField getTfAlastname() {
		return tfAlastname;
	}

	public void setTfAlastname(JTextField tfAlastname) {
		this.tfAlastname = tfAlastname;
	}

	public JTextField getTfAemail() {
		return tfAemail;
	}

	public void setTfAemail(JTextField tfAemail) {
		this.tfAemail = tfAemail;
	}

	public JButton getBtAsave() {
		return btAsave;
	}

	public void setBtAsave(JButton btAsave) {
		this.btAsave = btAsave;
	}

	public JButton getBtAcan() {
		return btAcan;
	}

	public void setBtAcan(JButton btAcan) {
		this.btAcan = btAcan;
	}

	public JComboBox getCxAlang() {
		return cxAlang;
	}

	public void setCxAlang(JComboBox cxAlang) {
		this.cxAlang = cxAlang;
	}

}
